package com.synesthesiaconsulting.gwt.resources.client;

import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Panel;

/**
 * Created by IntelliJ IDEA.
 * User: ageer
 * Date: Jul 24, 2008
 * Time: 5:23:32 PM
 * To change this template use File | Settings | File Templates.
 */
public class GWTWidgetActionUnit implements IActionUnit {
    private Widget widget;
    private Boolean clearFirst;

    public GWTWidgetActionUnit() {
        widget = new Widget();
        clearFirst = false;
    }

    public GWTWidgetActionUnit(Widget widget) {
        this.widget = widget;
        clearFirst = false;
    }

    public GWTWidgetActionUnit(Widget widget, Boolean clearFirst) {
        this.widget = widget;
        this.clearFirst = clearFirst;
    }

    public void applyAction(Object a) {
        try {
            Panel w = (Panel) a;
            if (clearFirst) w.clear();
            w.add(widget);
        } catch (Exception e) {
            System.err.print("Error. Attempting to apply widget to non-panel object");
        }
    }

    public String toString() {
        return "Widget Action";
    }

}
